package com.ruoyi.exam.service.impl;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.exam.domain.PExamQuestion;
import com.ruoyi.exam.domain.PExamRecordLog;
import com.ruoyi.exam.mapper.PExamQuestionMapper;
import com.ruoyi.exam.mapper.PExamRecordLogMapper;
import com.ruoyi.exam.service.IPExamRecordLogService;
import com.ruoyi.exam.vo.ExamByLogResult;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * 考试记录Service业务层处理
 *
 * @author jiadun
 * @date 2022-01-10
 */
@Service
public class PExamRecordLogServiceImpl implements IPExamRecordLogService
{
    @Resource
    private PExamRecordLogMapper pExamRecordLogMapper;

    @Resource
    private PExamQuestionMapper pExamQuestionMapper;

    /**
     * 查询考试记录
     *
     * @param id 考试记录主键
     * @return 考试记录
     */
    @Override
    public PExamRecordLog selectPExamRecordLogById(Long id)
    {
        return pExamRecordLogMapper.selectPExamRecordLogById(id);
    }

    /**
     * 查询考试记录列表
     *
     * @param pExamRecordLog 考试记录
     * @return 考试记录
     */
    @Override
    public List<PExamRecordLog> selectPExamRecordLogList(PExamRecordLog pExamRecordLog)
    {
        return pExamRecordLogMapper.selectPExamRecordLogList(pExamRecordLog);
    }

    /**
     * 新增考试记录
     *
     * @param pExamRecordLog 考试记录
     * @return 结果
     */
    @Override
    public int insertPExamRecordLog(PExamRecordLog pExamRecordLog)
    {
        pExamRecordLog.setCreateTime(DateUtils.getNowDate());
        return pExamRecordLogMapper.insertPExamRecordLog(pExamRecordLog);
    }

    /**
     * 修改考试记录
     *
     * @param pExamRecordLog 考试记录
     * @return 结果
     */
    @Override
    public int updatePExamRecordLog(PExamRecordLog pExamRecordLog)
    {
        pExamRecordLog.setUpdateTime(DateUtils.getNowDate());
        return pExamRecordLogMapper.updatePExamRecordLog(pExamRecordLog);
    }

    /**
     * 批量删除考试记录
     *
     * @param ids 需要删除的考试记录主键
     * @return 结果
     */
    @Override
    public int deletePExamRecordLogByIds(Long[] ids)
    {
        return pExamRecordLogMapper.deletePExamRecordLogByIds(ids);
    }

    /**
     * 删除考试记录信息
     *
     * @param id 考试记录主键
     * @return 结果
     */
    @Override
    public int deletePExamRecordLogById(Long id)
    {
        return pExamRecordLogMapper.deletePExamRecordLogById(id);
    }

    @Override
    public ExamByLogResult selectPExamRecordLogByOne(PExamRecordLog pExamRecordLog) {
        return pExamRecordLogMapper.selectPExamRecordLogByOne(pExamRecordLog);
    }

    @Override
    public int addExamQuestions(PExamRecordLog pExamRecordLog) {
        PExamQuestion pExamQuestion = new PExamQuestion();
        pExamQuestion.setExamId(pExamRecordLog.getExamId());
        pExamQuestion.setQuestionIds(pExamRecordLog.getQuestionIds());
        pExamQuestion.setScores(pExamRecordLog.getScores());
        pExamQuestion.setDeleteFlag(new Long(0));
        pExamQuestion.setCreateTime(new Date());
        pExamQuestion.setCreateBy(pExamRecordLog.getCreateBy());
        pExamQuestionMapper.insertPExamQuestion(pExamQuestion);

        return 1;
    }

  @Override
  public int selectPExamRecordCount(PExamRecordLog pExamRecordLog) {
    return pExamRecordLogMapper.selectPExamRecordCount(pExamRecordLog);
  }
}
